#! /bin/bash
# *** Make the subission JARs

function printUsage() {
    cat <<EOF
 ** Usage: ./makeExeJar.sh <Flavor> [<username>]
    - Flavor is either "Sender" or "Receiver" or "All"
    - Make the executable Jars for your sender or receiver.
    - Specify a second parameter <username> to scp the recvFile.jar to user's 
      home directory on cs4700dns.ccs.neu.edu
EOF
}

function makeSender() {
   echo "Making sendFile.jar"
   runnable="sendFile.jar";
   manifest=sender.mf
   cp -r bin/common .
   cp -r bin/sender .
   jar cvfm $runnable $manifest common sender
   rm -r common
   rm -r sender

   if [ "$1" != "" ]; then
   	scp sendFile.jar $1@cs4700dns.ccs.neu.edu:~
   	scp sendFile.jar $1@digdug.ccs.neu.edu:~
   fi
}

function makeReceiver() {
   echo "Making recvFile.jar"
   runnable="recvFile.jar";
   manifest=receiver.mf
   cp -r bin/common .
   cp -r bin/receiver .
   jar cvfm $runnable $manifest common receiver
   rm -r common
   rm -r receiver

   if [ "$1" != "" ]; then
   	scp recvFile.jar $1@cs4700dns.ccs.neu.edu:~
   fi
}

if [ "$1" == "" ]; then
   printUsage;
   exit 1;
fi

if [ "$1" == "Sender" ]; then
   makeSender $2;
elif [ "$1" == "Receiver" ]; then
   makeReceiver $2;
elif [ "$1" == "All" ]; then
   makeSender $2;
   makeReceiver $2;
else
   printUsage;
   exit 1;
fi
